package com.ruoyi.heima.listener;

import com.ruoyi.heima.properties.SensitiveWordProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class SensitiveWordFilter {
    @Autowired
    private SensitiveWordProperties sensitiveWordProperties;

    public boolean isContentValid(String content) {
        return !sensitiveWordProperties.getSensitiveWords().stream()
                .anyMatch(content::contains);
    }

    public List<String> findMatchedWords(String content) {
        return sensitiveWordProperties.getSensitiveWords().stream()
                .filter(content::contains)
                .collect(Collectors.toList());
    }
}